/*
 * SymbolGenerator.java
 *
 * Created on July 5, 2006, 8:55 PM
 *
 */

package galronnlp.util;

import java.util.Hashtable;
import java.util.Enumeration;
import java.lang.Integer;

/**
 *
 * @author Daniel A. Galron
 */
public class SymbolGenerator {
    
    private Hashtable<String, Integer> symbolTable;
    Integer nextInt = new Integer(-1);
    /** Creates a new instance of SymbolGenerator */
    public SymbolGenerator() {
        symbolTable = new Hashtable<String, Integer>();
    }

    public int size() {
        return symbolTable.size();
    }    
    
    public Symbol create(String T) {
        if(symbolTable.containsKey(T)) {
            return new Symbol(T, symbolTable.get(T).intValue());
        } else {
            nextInt = new Integer(nextInt.intValue() + 1);
            symbolTable.put(T, nextInt);
            return new Symbol(T, nextInt.intValue());
        }
    }
    
    public String toString() {
        String ret = "----------------------------\n";
        for(Enumeration<String> e = symbolTable.keys(); e.hasMoreElements(); ) {
            String next = e.nextElement();
            ret += next + ": " + (Integer)symbolTable.get(next) + "\n";
        }
        ret += "--------------------------------\n";
        return ret;
    }
    
}
